package 公司真题.瑛太莱;

import java.util.Scanner;

public class _斜线打印数组 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int m = sc.nextInt();
        sc.nextLine();
        int n = sc.nextInt();
        sc.nextLine();
        int[][] arr = new int[m][n];
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                arr[i][j] = sc.nextInt();
            }
            sc.nextLine();
        }
        // 打印数组
//        for (int i = 0; i < m; i++) {
//            for (int j = 0; j < n; j++) {
//                System.out.print(arr[i][j] + " ");
//            }
//            System.out.println();
//        }
        // 开始斜线打印
        // myPrint()方法用于打印当前斜线上的元素
        for (int i = 0; i < n; i++) {
            myPrint(arr, 0, i);
        }

        for (int i = 1; i < m; i++) {
            myPrint(arr, i, n - 1);
        }
    }

    private static void myPrint(int[][] arr, int x, int y) {
        int m = arr.length;
        int n = arr[0].length;
        while (x < m && y >= 0) {
            if (x == m - 1 && y == n - 1) {
                System.out.print(arr[x][y]);
            } else {
                System.out.print(arr[x][y] + ",");
            }
            x++;
            y--;
        }
    }
}
